#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: seek.py
# Description: 
#   To change the file object’s position, use f.seek(offset, from_what). 
#   The position is computed from adding offset to a reference point; 
#   the reference point is selected by the from_what argument. 
#   A from_what value of 0 measures from the beginning of the file, 
#   1 uses the current file position, and 2 uses the end of the file as 
#   the reference point. from_what can be omitted and defaults to 0, 
#   using the beginning of the file as the reference point.
# Edit History: 
#   2011-10-18    File created.
#===============================================================================
f = open('seek.py', 'r')
f.seek(5) # Go to the 6th byte in the file
print(f.read(1))
f.seek(-3, 2) # Go to the 3rd byte before the end
print(f.read(1)) # 1234
